//
//  FindTravellingTableCell.m
//  AroundTheWorld
//
//  Created by dllo on 16/5/25.
//  Copyright © 2016年 IfelseGo an. All rights reserved.
//

#import "FindTravellingTableCell.h"

@implementation FindTravellingTableCell
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self doSometing];
    }
    return self;
}

-(void)doSometing{
    
}

- (void)setMyModel:(FindTravellingModel *)myModel
{
    _myModel = myModel;
    self.titleLabel.text = _myModel.title;
    self.citysLabel.text = _myModel.citys_str;
    self.userNameLabel.text = _myModel.username;
        self.viewsLabel.text = [NSString stringWithFormat:@"%ld", _myModel.views];
    self.replayLabel.text = [NSString stringWithFormat:@"%ld",_myModel.replys];

    NSString *statDate = [self number1970ChangeDate:_myModel.start_time];
    NSString *endDate = [self number1970ChangeDate:_myModel.end_time];
    self.dataLabel.text = [NSString stringWithFormat:@"%@ - %@", statDate, endDate];
    self.publishLabel.text =  [self intervalSinceNow:_myModel.publish_time];

    self.dk_backgroundColorPicker = DKColorPickerWithRGB(0xffffff,0xCFCFCF);
}
//数字字符串转为日期字符串
- (NSString *)number1970ChangeDate:(NSString *)numberDate{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"YYYY.MM.dd";
    NSInteger numberTime = [numberDate integerValue];
    NSDate *Date = [NSDate dateWithTimeIntervalSince1970:numberTime];
    NSString *strDate = [formatter stringFromDate:Date];
    return strDate;
}
//一个时间距现在的时间
- (NSString *)intervalSinceNow:(NSString *)theDate
{
    NSDateFormatter *date=[[NSDateFormatter alloc] init];
    date.dateFormat=@"yyyy-MM-dd HH:mm:ss";
    
    NSDate *startTime = [NSDate dateWithTimeIntervalSince1970:[theDate integerValue]];
    NSTimeInterval start=[startTime timeIntervalSince1970] * 1;
    NSDate *nowDate = [[NSDate alloc] init];
    NSTimeInterval now=[nowDate timeIntervalSince1970]*1;
    
    NSString *timeString=@"";
    NSTimeInterval cha=now - start;
    
    if (cha/3600<1) {
        timeString = [NSString stringWithFormat:@"%f", cha/60];
        timeString = [timeString substringToIndex:timeString.length-7];
        timeString=[NSString stringWithFormat:@"%@分钟前", timeString];
    }
    if (cha/3600>1&&cha/86400<1) {
        timeString = [NSString stringWithFormat:@"%f", cha/3600];
        timeString = [timeString substringToIndex:timeString.length-7];
        timeString=[NSString stringWithFormat:@"%@小时前", timeString];
    }
    if (cha/86400>1)
    {
        timeString = [NSString stringWithFormat:@"%f", cha/86400];
        timeString = [timeString substringToIndex:timeString.length-7];
        timeString=[NSString stringWithFormat:@"%@天前", timeString];
    }
    return timeString;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
